//
//  CSBalanceCell.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/11/14.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSBalanceCell.h"
#import "CSEditView.h"


@interface CSBalanceCell ()

/////vContent
//@property (nonatomic,weak) UIView * vContent;
/////vTitle
//@property (nonatomic,weak) UIView * vTitle;
///lblName
@property (nonatomic,weak) UILabel * lblName;
/// 余额
@property (nonatomic,weak) UILabel * lblBalance;
///editViewBalance
@property (nonatomic,weak) CSEditView * editViewBalance;
///evwShouldGather
@property (nonatomic,weak) CSEditView * evwShouldGather;
/// 批次 batch
@property (nonatomic,weak) UIButton * btnBatch;
/// 发货金额
@property (nonatomic,weak) UILabel * lblMoney;

@end

@implementation CSBalanceCell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - methods

- (void)distributeBalanceCell {
    
    CGFloat moneyF = self.saleModelBalance.sTotalMoney;
    NSString * moneyStr = [NSString stringWithFormat:@"%.2f", moneyF];
    
    self.lblName.text = self.saleModelBalance.sName;
//    self.lblBalance.text = @"余额：0.00";
    self.evwShouldGather.editViewDict = @{@"title":@"应收：", @"edit":moneyStr, @"fontSize":@(13)};
    self.lblMoney.text = [NSString stringWithFormat:@"发货金额：%.2f", moneyF];
}


#pragma mark - setupUI
- (void)setupUI {
    
    //vTitle
    UIView * vTitle = [[UIView alloc] init];
    [self.contentView addSubview:vTitle];
    vTitle.backgroundColor = kColorBar;
    
    [vTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.bottom.equalTo(self.contentView);
        make.width.offset(100);
    }];
    
    //lblName
    UILabel * lblName = [UILabel gx_labelWithText:@"综合品牌" fontSize:14 color:kColorWhite];
    [vTitle addSubview:lblName];
    lblName.textAlignment = NSTextAlignmentCenter;
    lblName.backgroundColor = kColorBar;
    lblName.font = [UIFont systemFontOfSize:14];
    
    [lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_centerY).offset(-5);
        make.leading.trailing.equalTo(vTitle);
    }];
    
    // 余额
    UILabel * lblBalance = [UILabel gx_labelWithText:@" 余额：0.00" fontSize:13 color:kColorWhite];
    [vTitle addSubview:lblBalance];
    lblBalance.textAlignment = NSTextAlignmentLeft;
    lblBalance.backgroundColor = kColorBar;
    lblBalance.font = [UIFont systemFontOfSize:14];
    
    [lblBalance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_centerY).offset(5);
        make.leading.trailing.equalTo(vTitle);
    }];
    
    //editViewBalance
    CSEditView * editViewBalance = [CSEditView editViewWithDict:@{@"title":@"余额：", @"edit":@"0", @"fontSize":@(13)}];
    [self.contentView addSubview:editViewBalance];
    editViewBalance.lineColor = [UIColor gx_colorWithRed:232 green:232 blue:232];
    
    [editViewBalance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(2);
        make.leading.equalTo(vTitle.mas_trailing).offset(8);
        make.width.offset(100);
        make.height.offset(30);
    }];
    
    //evwShouldGather
    CSEditView * evwShouldGather = [CSEditView editViewWithDict:@{@"title":@"应收：", @"edit":@"0", @"fontSize":@(13)}];
    [self.contentView addSubview:evwShouldGather];
    evwShouldGather.lineColor = [UIColor gx_colorWithRed:232 green:232 blue:232];
    
    [evwShouldGather mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(editViewBalance);
        make.trailing.equalTo(self.contentView).offset(-8);
        make.size.equalTo(editViewBalance);
    }];
    
    // 批次 batch
    UIButton * btnBatch = [UIButton gx_textButton:@"批次" fontSize:15 normalColor:kColorWhite selectedColor:kColorWhite];
    [self.contentView addSubview:btnBatch];
    btnBatch.backgroundColor = [UIColor grayColor];
    [btnBatch setTitleEdgeInsets:UIEdgeInsetsMake(4, 4, 4, 4)];
    btnBatch.layer.cornerRadius = 8;
    
    [btnBatch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(35);
        make.trailing.equalTo(self.contentView).offset(-8);
        make.size.mas_offset(CGSizeMake(70, 25));
    }];

    // 发货金额
    UILabel * lblMoney = [UILabel gx_labelWithText:@"发货金额：0.00" fontSize:13 color:[UIColor blackColor]];
    [self.contentView addSubview:lblMoney];
    
    [lblMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(editViewBalance);
        make.trailing.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(65);
        make.height.offset(22);
        make.bottom.equalTo(self.contentView).offset(-5);
    }];
    lblMoney.text = @"0";

    //
//    self.vContent = vContent;
//    self.vTitle = vTitle;
    self.lblName = lblName;
    self.lblBalance = lblBalance;
    self.editViewBalance = editViewBalance;
    self.evwShouldGather = evwShouldGather;
    self.btnBatch = btnBatch;
    self.lblMoney = lblMoney;
}

#pragma mark - setter & getter
- (void)setSaleModelBalance:(TSaleInfoModel *)saleModelBalance {
    _saleModelBalance = saleModelBalance;

    //distribute
    [self distributeBalanceCell];
}




@end
